<style type="text/css">
    .ui-datepicker-calendar {display: none;}
</style>
<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading">
                <h3 class="panel-title">财务月度库存成本报表</h3>
            </div>
            <div class="panel-body">
                <form action="__URL__/index" method="get">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-2  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">SKU</span>
                                <input class="form-control" type="text" name="sku" onkeyup="this.value=trim(this.value)"
                                       value="{$_GET['sku']|default=''}">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">公司主体</span>
                                <select name="enterprise_dominant" id="enterprise_dominant" class="form-control">
                                    <option value="">--请选择--</option>
                                    <volist name="enterprise_dominant" id="val" key="num">
                                        <option value="{$num}">{$val}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-2  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">期初月份</span>
                                <input name="warehouse_date" id="warehouse_date" class="form-control" readonly="readonly"/>

                            </div>
                        </div>
                        <div class="col-sm-12 col-md-5  add-space">
                            <input class="btn btn-primary" type="submit" id="serach" value="查询">
                            <button class="btn btn-primary" type="button" id="cost_download">下载</button>
                            <button class="btn btn-primary btn-info" type="button" data-toggle="modal"
                                    data-target="#btn_import">修正上个月份成本为0入库明细</button>
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <hr/>
                <div id="pageContent" class="well" style="min-width:600px;max-width:100%;overflow-x:scroll">
                    <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                        <thead>
                        <tr>
                            <th rowspan="2">sku</th>
                            <th rowspan="2">中文名称</th>
                            <th rowspan="2">主体</th>
                            <th colspan="2">期初</th>
                            <th colspan="{$type_length['in']*2+2}">本期入</th>
                            <th colspan="{$type_length['out']*2+2}">本期出</th>
                            <th colspan="2">期末</th>
                        </tr>
                        <tr>
                            <th>期初数量</th>
                            <th>期初成本</th>
                            <foreach name="stock_in_type" item="vo">
                                <th>{$vo}数量</th>
                                <th>{$vo}成本</th>
                            </foreach>
                            <th>入库数量合计</th>
                            <th>入库成本合计</th>
                            <foreach name="stock_out_type" item="vo">
                                <th>{$vo}数量</th>
                                <th>{$vo}成本</th>
                            </foreach>
                            <th>出库数量合计</th>
                            <th>出库成本合计</th>
                            <th>期末数量</th>
                            <th>期末成本</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php if(!empty($inventoryCostDetail)) {
                                foreach ($inventoryCostDetail as $data) {?>
                                    <tr>
                                    <td><?php echo $data['sku'] ?></td>
                                    <td><?php echo $data['sku_name'] ?></td>
                                    <td><?php echo $data['enterprise_dominant'] ?></td>
                                    <td><?php echo $data['beginning_quantity'] ?></td>
                                    <td><?php echo $data['beginning_cost'] ?></td>
                                    <?php foreach($stock_in_type as $type_in => $in) {?>
                                        <td><?php echo $data['in_' . $type_in . '_quantity'] ?></td>
                                        <td><?php echo $data['in_' . $type_in . '_cost'] ?></td>
                                    <?php } ?>
                                    <td><?php echo $data['inTotalQuantity'] ?></td>
                                    <td><?php echo $data['inTotalCost'] ?></td>
                                    <?php foreach($stock_out_type as $type_out => $out) {?>
                                        <td><?php echo $data['out_' . $type_out . '_quantity'] ?></td>
                                        <td><?php echo $data['out_' . $type_out . '_cost'] ?></td>

                                    <?php } ?>
                                    <td><?php echo $data['outTotalQuantity'] ?></td>
                                    <td><?php echo $data['outTotalQuantity'] ?></td>
                                    <td><?php echo $data['end_quantity'] ?></td>
                                    <td><?php echo $data['end_cost'] ?></td>
                                    </tr>
                        <?php   }
                              } ?>
                        </tbody>
                    </table>
                </div>
                <div class="clearfix clear"></div>
                <div class="row">
                    <div class="col-md-6 pull-left">
                        <label>每页 50 条记录
                            显示 1 到 50 项，共 {$count}项</label>
                    </div>
                    <div class="col-md-6">
                        <div class="page pull-right" style="padding: 0;margin: 0">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!--导入文件 -->
<div class="modal fade" id="btn_import">
    <div class="modal-dialog">

        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">关闭</span></button>
                <h4 class="modal-title">导入文件<span style="color: red">（导入请使用xlsx类型的）</span></h4>
            </div>
            <form action="__URL__/upload_cost" method="post" enctype="multipart/form-data" id="upSku">
                <div class="modal-body form-horizontal">
                    <div class="alert alert-info top20" role="alert">
                        <p>入库明细: <a href="javascript:void(0)" id="download" >成本为0入库明细</a></p></div>

                    <div class="form-group"><label class="col-md-3 control-label required">上传文件</label>

                        <div class="col-md-4"><input name="file" class="form-control" data-val="true"
                                                     data-val-required="请选择[上传文件]!" id="File" type="file" value="">
                        </div>
                    </div>

                    <div class="form-group">
                        <button id="submit-button" type="submit" class="col-md-offset-3 col-md-1 btn btn-danger">上传
                        </button>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
            <button type="button" class="btn" data-dismiss="modal">取消</button>
        </div>
    </div>
</div>

<script>
    $(function(){
        $('#warehouse_date').datetimepicker({
            format: 'Y-m',
            todayBtn: true,
            startView: 'year',
            minView:'year',
            maxView:'decade',
            language:'zh-CN'
        });

        $("#download").click(function () {
            var warehouse_date = $("#warehouse_date").val();
            if (!warehouse_date) {
                layer.msg("请先输入月份！",{'icon':'5'});
                return false;
            }

            var fileName="入库成本导入模板";
            window.location.href ="__URL__/warehouseCostDownload?"+"&fileName="+fileName+"&warehouse_date="+warehouse_date;
        });

        $("#cost_download").click(function () {
            var sku = $("input[name='sku']").val();
            var enterprise_dominant = $("select[name='enterprise_dominant']").val();
            var warehouse_date = $("#warehouse_date").val();

            window.location.href ="__URL__/index?download=1&sku="+sku+"&enterprise_dominant="+enterprise_dominant+"&warehouse_date="+warehouse_date;
        })
    });


    function trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }

</script>